<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=yes">
  
  
  <title>  Tomcat配置域名访问 |   写夜子的个人博客 </title>

 
  
    <link rel="icon" href="/images/favicon.png">
  


  <link rel="stylesheet" href="/nayo.min.css"> 
</head>  
  <body>   
    
      <header class="header">
	
  <nav class="header-nav">        
   
    <span class="iconfont icon-menu mobile-toggle"></span>   	

    <div class="header-menu">          
              
            
              <a class="header-menu-link" id="header-menu-home" href="/">首页</a>     
            
            
            
              <a class="header-menu-link" id="header-menu-archives" href="/archives">归档</a>     
            
            
            
              <a class="header-menu-link" id="header-menu-tags" href="/tags">标签</a>     
            
            
            
              <a class="header-menu-link" id="header-menu-about" href="/about">关于</a>     
            
            
            
              <a class="iconfont icon-menu-search header-menu-link" id="header-menu-search"></a>
            
                
    </div>  
    
  </nav>
</header>   

      <div class="container">       
          
          
            <section class="main">  
          

          <article class="post">
  
	<div class="post-header">

	<p class="post-title">	
		Tomcat配置域名访问
	</p>
			

	<div class="meta-info">	
	<span>
		10月 03, 2018
	</span>

	
	
		<i class="iconfont icon-words"></i>
		<span>
			2938
		</span>
	
</div>

</div> 
	 

	  <div class="post-content slideDownMin">

		

			
					<h3 id="Tomcat基本配置"><a href="#Tomcat基本配置" class="headerlink" title="Tomcat基本配置"></a>Tomcat基本配置</h3><p>  我们在构建一个网站的时候,常常选择Tomcat作为服务器的工程项目容器.所以我们需要将域名配置到Tomcat上,也就是说我们可以通过域名直接访问我们的网站.<br>  <a id="more"></a><br>  先将你的项目打包上传至服务器.然后放置到Tomcat目录下的webapps下.<br>  <img src="http://wx1.sinaimg.cn/mw690/89296167gy1fvvasnv5rwj211w0hwn05.jpg" alt="文件"></p>
<p>  然后进入conf目录下,打开server.xml进行编辑.<br>  配置域名能直接访问项目,需要在server.xml添加以下代码：<br>  <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">  &lt;Host name=&quot;www.xieyezi.com&quot;  appBase=&quot;webapps&quot;</span><br><span class="line">      unpackWARs=&quot;true&quot; autoDeploy=&quot;true&quot;&gt;</span><br><span class="line">      &lt;Context docBase=&quot;C:\Program Files\apache-tomcat-9.0.7-windows-x64\apache-tomcat-9.0.7\webapps\Xydesign&quot; path=&quot;&quot; reloadable=&quot;true&quot;/&gt;</span><br><span class="line">  &lt;!-- SingleSignOn valve, share authentication between web applications</span><br><span class="line">       Documentation at: /docs/config/valve.html --&gt;</span><br><span class="line">  &lt;!--</span><br><span class="line">  &lt;Valve className=&quot;org.apache.catalina.authenticator.SingleSignOn&quot; /&gt;</span><br><span class="line">  --&gt;</span><br><span class="line"></span><br><span class="line">  &lt;!-- Access log processes all example.</span><br><span class="line">       Documentation at: /docs/config/valve.html</span><br><span class="line">       Note: The pattern used is equivalent to using pattern=&quot;common&quot; --&gt;</span><br><span class="line">  &lt;Valve className=&quot;org.apache.catalina.valves.AccessLogValve&quot; directory=&quot;logs&quot;</span><br><span class="line">         prefix=&quot;localhost_access_log&quot; suffix=&quot;.txt&quot;</span><br><span class="line">         pattern=&quot;%h %l %u %t &amp;quot;%r&amp;quot; %s %b&quot; /&gt;</span><br><span class="line"></span><br><span class="line">&lt;/Host&gt;</span><br></pre></td></tr></table></figure></p>
<ol>
<li>配置项目通过域名访问    </li>
</ol>
  <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&lt;Host name=&quot;www.xieyezi.com&quot;  appBase=&quot;hcode&quot;</span><br><span class="line">          unpackWARs=&quot;true&quot; autoDeploy=&quot;true&quot;&gt;</span><br></pre></td></tr></table></figure>
<p>  将Host标签的name设置为你的域名,appBase设置为你的项目的路径(可以为绝对路径和相对路径,你可以看见我这里设置为相对路径).<br>  配置完成即可保存,然后通过 <a href="http://www.xieyezi.com/Xydesign" target="_blank" rel="noopener">http://www.xieyezi.com/Xydesign</a> 访问.</p>
<ol start="2">
<li>配置项目名缺省进行访问     </li>
</ol>
<p>  一般的,我们一般是直接访问域名就进行访问.而不是通过在域名末尾添加项目名进行访问.<br>  <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;Context docBase=&quot;hcode&quot; path=&quot;&quot; /&gt;</span><br></pre></td></tr></table></figure></p>
<p>  其中,docBase即为项目的绝对路径,此时通过 <a href="http://www.xieyezi.com" target="_blank" rel="noopener">http://www.xieyezi.com</a> 即可进行项目名缺省的访问.</p>
<ol start="3">
<li>部署多个项目到Tomcat     </li>
</ol>
<p>  将你的项目打包放置到webapps路径下,然后在server.xml的Host下面添加以下代码:<br>  <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;Context path=&quot;&quot; docBase=&quot;&quot; debug=&quot;0&quot; reloadable=&quot;false&quot;/&gt;</span><br></pre></td></tr></table></figure></p>
<p>  将path标签设置为<code>/你的项目名</code>,docBase设置为<code>你的项目根目录的绝对路径</code>.<br>  配置完成即可保存,然后通过 <a href="http://www.xieyezi.com/项目名" target="_blank" rel="noopener">http://www.xieyezi.com/项目名</a> 访问.</p>
<ol start="4">
<li>https访问配置    </li>
</ol>
<p>  在server.xml添加以下代码:<br>  <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&lt;Connector port=&quot;443&quot; protocol=&quot;org.apache.coyote.http11.Http11Protocol&quot;</span><br><span class="line">             maxThreads=&quot;150&quot; SSLEnabled=&quot;true&quot; scheme=&quot;https&quot; secure=&quot;true&quot;</span><br><span class="line">             clientAuth=&quot;false&quot;</span><br><span class="line">              sslProtocol=&quot;TLS&quot;</span><br><span class="line">              keystoreFile=&quot;/home/doc/keys/213972284410468.pfx&quot;</span><br><span class="line">              keystoreType=&quot;PKCS12&quot;</span><br><span class="line">              keystorePass=&quot;213972284410468&quot;         /&gt;</span><br></pre></td></tr></table></figure></p>
<p>  添加keystoreFile,keystoreType,keystorePass即可进行https访问.</p>
<ol start="5">
<li>自动跳转到https连接    </li>
</ol>
<p>  如果希望输入http链接时自动跳转到https,需要在web.xml中添加如下内容:<br>  <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">&lt;login-config&gt;</span><br><span class="line">              &lt;!-- Authorization setting for SSL --&gt;</span><br><span class="line">              &lt;auth-method&gt;CLIENT-CERT&lt;/auth-method&gt;</span><br><span class="line">                      &lt;realm-name&gt;Client Cert Users-only Area&lt;/realm-name&gt;</span><br><span class="line">      &lt;/login-config&gt;</span><br><span class="line">      &lt;security-constraint&gt;</span><br><span class="line">              &lt;!-- Authorization setting for SSL --&gt;</span><br><span class="line">              &lt;web-resource-collection &gt;</span><br><span class="line">                      &lt;web-resource-name &gt;SSL&lt;/web-resource-name&gt;</span><br><span class="line">                      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;</span><br><span class="line">              &lt;/web-resource-collection&gt;</span><br><span class="line">              &lt;user-data-constraint&gt;</span><br><span class="line">                      &lt;transport-guarantee&gt;CONFIDENTIAL&lt;/transport-guarantee&gt;</span><br><span class="line">              &lt;/user-data-constraint&gt;</span><br><span class="line">      &lt;/security-constraint&gt;</span><br></pre></td></tr></table></figure></p>
<p>  以上内容位置在<code>&lt;/web-app&gt;</code>内,添加后输入http访问时会自动跳转到https连接.</p>
  	
					
	  </div>     
	  

	
<div class="post-meta">
      	

      
        <i class="iconfont icon-tag"></i>     
          <a class="tag-link" href="/tags/Tomcat/">Tomcat</a>    
      	
</div>





<div class="post-footer">
  <div class="pf-left">
      <img class="pf-avatar" src="http://wx2.sinaimg.cn/mw690/89296167gy1fu5ph67x17j21kw1kwhdu.jpg">
      <p class="pf-des">hi,我是写夜子,希望你有愉快的一天.</p>
  </div>

  <div class="pf-right">           
      <div class="pf-links">
        




<span class="donate-btn">
	<span class="iconfont icon-donate"></span>
</span>


<div id="donate-box" class="sildeUpMin">

	<span class="donate-cancel iconfont icon-cancel"></span>

	<div class="donate-img-box">
		<img id="donate-qr-wechat" class="noLazyLoad donate-img" src="/images/donate1.png" alt="No Donate Image!">	
		<img id="donate-qr-alipay" class="noLazyLoad donate-img" src="/images/donate2.png" alt="No Donate Image!">	
	</div>

	<span class="donate-word">世界美好 你也是</span>

	<div class="donate-list">
		<span class="iconfont icon-donate-wechat"></span>
		<span class="iconfont icon-donate-alipay"></span>
	</div>

</div>

 
        
	
<script id="-mob-share" src="http://f1.webshare.mob.com/code/mob-share.js?appkey=21d601593a1de"></script>
	
	<span class="share-btn">
	<span class="iconfont icon-share"></span>
	</span>


	<div class="-mob-share sildeUpMin">
		   			             
            <a class="iconfont  icon-share-qq -mob-share-qq"></a>		
     	   			             
            <a class="iconfont  icon-share-weixin -mob-share-weixin"></a>		
     	   			             
            <a class="iconfont  icon-share-weibo -mob-share-weibo"></a>		
     	   			             
            <a class="iconfont  icon-share-douban -mob-share-douban"></a>		
     	   			             
            <a class="iconfont  icon-share-facebook -mob-share-facebook"></a>		
     	   			             
            <a class="iconfont  icon-share-twitter -mob-share-twitter"></a>		
     	   			             
            <a class="iconfont  icon-share-google -mob-share-google"></a>		
     	   
	</div>	

      </div>  
    <nav class="pf-paginator">
      
         
          <a href="/2018/10/08/Vue-cli 3.0解决跨域问题/" data-hover="Vue-cli 3.0解决跨域问题">上一篇</a>      
            
        
      
        
        <a href="/2018/09/28/css超出部分显示省略号/" data-hover="css超出部分显示省略号"> 下一篇</a>
            
  </nav>   
  </div>
</div> 
	
	
</article>

          </section> 
      </div>            
    
    <a id="backTop">
      <span>
        <i class="iconfont icon-backtotop"></i>
      </span>
    </a> 

  
    
    <div class="search-container sildeUpMin">
        <div class="search-header">
            <input type="text" placeholder="输入你想搜索的" id="search-input" class="search-input">  
            <span class="search-cancel iconfont icon-cancel"></span>
        </div>
        <div id="search-result" class="search-result"></div>
    </div>
 
     <div class="mobile-menu">      

      
      <img class="mobile-menu-icon" src="/images/favicon.png">   
      

         
            

            <a class="mobile-menu-link" href="/">首页
            </a>
            
         
            

            <a class="mobile-menu-link" href="/archives">归档
            </a>
            
         
            

            <a class="mobile-menu-link" href="/tags">标签
            </a>
            
         
            

            <a class="mobile-menu-link" href="/about">关于
            </a>
            
         
                          

            <a class="mobile-menu-link mobile-menu-search" href="#">搜索 </a>                 
            
         
      
</div>        
    


<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?636802045446222199ae541e32c8133e"; 
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>





     
    




<footer id="footer">


		<div class="footer-copyright">
		&copy;
		
		2018-
		
		2020

		Xieyezi
		<br>

		Copyright
		<a href="https://github.com/xieyezi" target="_blank">Xieyezi</a>
		</div>

</footer>
   

  

    <script src="/nayo.bundle.js"></script>           
  </body>        
</html>